fix(core): Inject replayId into trace context for buffer mode errors#5754
Open
romtsn wants to merge 5 commits into
Open
fix(core): Inject replayId into trace context for buffer mode errors#5754romtsn wants to merge 5 commits into
romtsn wants to merge 5 commits into
Conversation
📲 Install BuildsAndroid
|
Contributor
Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 39e4c55 | 352.43 ms | 446.94 ms | 94.51 ms |
| 048e40b | 322.47 ms | 362.69 ms | 40.22 ms |
| 94ec28b | 317.49 ms | 407.84 ms | 90.35 ms |
| a5d4b7b | 413.28 ms | 506.54 ms | 93.26 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 39e4c55 | 0 B | 0 B | 0 B |
| 048e40b | 0 B | 0 B | 0 B |
| 94ec28b | 0 B | 0 B | 0 B |
| a5d4b7b | 0 B | 0 B | 0 B |
Previous results on branch: rz/fix/replay-error-linkage
Startup times
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 7dd24bc | 315.35 ms | 363.57 ms | 48.22 ms |
| 4f9605b | 382.72 ms | 476.24 ms | 93.52 ms |
| 9fbe087 | 391.26 ms | 480.70 ms | 89.44 ms |
| 48dcd0f | 322.68 ms | 374.14 ms | 51.46 ms |
| 01678a6 | 315.83 ms | 347.92 ms | 32.09 ms |
| e6285ac | 315.38 ms | 353.88 ms | 38.50 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 7dd24bc | 0 B | 0 B | 0 B |
| 4f9605b | 0 B | 0 B | 0 B |
| 9fbe087 | 0 B | 0 B | 0 B |
| 48dcd0f | 0 B | 0 B | 0 B |
| 01678a6 | 0 B | 0 B | 0 B |
| e6285ac | 0 B | 0 B | 0 B |
In buffer mode, the scope's replayId is empty until captureReplay() is called. The transaction's baggage is frozen before that, so the DSC in the envelope header has no replay_id — breaking error-to-replay linkage. After captureReplay() sets the replayId on scope, force-set it on the transaction's frozen baggage via Baggage.forceSetReplayId() so the envelope header carries the correct replay_id in the DSC. This matches the JS SDK's approach of updating the DSC after buffer-to- session conversion. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
43dceab to
8c8db4b
Compare
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
e63a32e to
6f89328
Compare
romtsn
commented
Jul 13, 2026
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit aab9e17. Configure here.
aab9e17 to
64766b2
Compare
Read scope.getReplayId() which is only set when on-error sampling succeeds. Using ReplayController.getReplayId() would return the buffer's internal ID even when sampling rejected the replay. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
64766b2 to
fa65f2e
Compare
markushi
approved these changes
Jul 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

📜 Description
In buffer mode, the scope's
replayIdis intentionally empty untilcaptureReplay()is called (to avoid tagging events with a replay that may never be sent). However, the event's DSC is built from the active transaction's frozen baggage, which was frozen beforecaptureReplay()set thereplayId. This means error events that trigger a buffer replay flush have noreplay_idin their DSC, breaking error-to-replay linkage.After
captureReplay()runs, we now force-set thereplayIdon the transaction's frozen baggage viaBaggage.forceSetReplayId(), so the envelope header carries the correctreplay_idin the DSC. This mirrors the JS SDK'ssetReplayIdOnDynamicSamplingContext.💡 Motivation and Context
Error events that trigger buffer-mode replay capture were not linked to the resulting replay, making it impossible to navigate from the error to its replay in the Sentry UI.
Example replay with a linked error event: https://sentry-sdks.sentry.io/explore/replays/49e737e2f6dc48f1a9c14692bd898bb7/?playlistEnd=2026-07-13T07:15:41&playlistStart=2026-07-06T07:15:41&project=5428559&query=&referrer=replayList&t_main=errors
💚 How did you test it?
SentryClientTestsuite passesreplay_id, and the error appears linked to the replay in Sentry📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps